package com.controller;

import com.controller.response.BuildingRentalResponse;
import com.dto.Result;
import com.entity.BuildingRentalInfo;
import com.service.BuildingRentalInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/building/rental")
public class BuildingRentalInfoController {
    
    @Autowired
    private BuildingRentalInfoService buildingRentalInfoService;

    @GetMapping("/code/{code}")
    public BuildingRentalResponse findByCode(@PathVariable("code") String code) {
        return buildingRentalInfoService.findByCode(code);
    }

    
    /**
     * 创建租赁信息
     * @param buildingRentalInfo 租赁信息
     * @return 结果
     */
    @PostMapping
    public void create(@RequestBody BuildingRentalInfo buildingRentalInfo) {
        buildingRentalInfoService.create(buildingRentalInfo);
    }
    
    /**
     * 删除租赁信息
     * @param id 租赁信息ID
     * @return 结果
     */
    @DeleteMapping("/{id}")
    public void delete(@PathVariable Integer id) {
        buildingRentalInfoService.deleteById(id);
    }
    
    /**
     * 更新租赁信息
     * @param buildingRentalInfo 租赁信息
     * @return 结果
     */
    @PutMapping
    public void update(@RequestBody BuildingRentalInfo buildingRentalInfo) {
        buildingRentalInfoService.update(buildingRentalInfo);
    }
    
    /**
     * 分页查询租赁信息
     * @param pageNum 页码，默认为1
     * @param pageSize 每页大小，默认为10
     * @return 租赁信息分页结果
     */
    @GetMapping
    public Page<BuildingRentalInfo> findAll(@RequestParam(defaultValue = "1") int pageNum,
                                            @RequestParam(defaultValue = "10") int pageSize) {
        return buildingRentalInfoService.findAll(pageNum, pageSize);
    }
    
    /**
     * 根据ID查询租赁信息详情
     * @param id 租赁信息ID
     * @return 租赁信息
     */
    @GetMapping("/{id}")
    public BuildingRentalResponse findById(@PathVariable Integer id) {
        return buildingRentalInfoService.findById(id);
    }


}